Skip to content

Fix remaining stdlib issues#847

Merged
martian56 merged 2 commits into
mainfrom
fix/open-issues-837-845
Jul 2, 2026
Merged

Fix remaining stdlib issues#847
martian56 merged 2 commits into
mainfrom
fix/open-issues-837-845

Conversation

@martian56

@martian56 martian56 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Fixes #837.
Fixes #839.
Fixes #840.
Fixes #841.
Fixes #842.
Fixes #843.
Fixes #844.
Fixes #845.

Also records the already-merged base32 padding fix from #838 in the changelog and patch version series.

Summary

  • clamp excessive std/fmt.format_float precision before float scaling overflows
  • keep Rng.weighted_choice entries reachable for huge positive weights
  • add checked TLS config builders and document std/tls in the guide/nav
  • sanitize HTTP response headers during serialization even after direct map mutation
  • reject raw invalid UTF-8 in JSON strings and align surrogate docs with parser behavior
  • update the stdlib charter and bump the workspace version to 2.19.10

Validation

  • cargo build
  • cargo test --test codegen_smoke -- --nocapture
  • cargo test --test golden v2_examples_match_golden_baselines -- --nocapture
  • cargo test --test fmt_golden -- --nocapture
  • mkdocs build --strict --site-dir C:\tmp\raven-docs-check\site
  • cargo fmt --check
  • cargo clippy --workspace --all-targets
  • cargo test --workspace --verbose

Summary by CodeRabbit

  • New Features

    • Added Standard Library TLS documentation and navigation, including client TLS streams, upgrade support, and configuration APIs.
    • Introduced checked TLS config builders that surface CA/certificate loading failures as results.
  • Bug Fixes

    • JSON parsing now rejects invalid UTF-8 and unpaired surrogates in \uXXXX.
    • HTTP response headers are validated and sanitized before serialization.
    • Improved weighted_choice to avoid overflow/eligibility issues with extreme weights.
    • format_float now clamps large precision requests to prevent non-terminating formatting.
    • Base32 decoding now enforces stricter RFC 4648 padding shape validation.
  • Tests

    • Updated smoke tests and examples for the new TLS/error and header/JSON behaviors.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9eb48dac-9a62-4497-9665-2d251f44549a

📥 Commits

Reviewing files that changed from the base of the PR and between 60d30d7 and 2c8c934.

📒 Files selected for processing (2)
  • examples/v2/stdlib_fmt.rv
  • stdlib/std/fmt.rv
✅ Files skipped from review due to trivial changes (1)
  • examples/v2/stdlib_fmt.rv
🚧 Files skipped from review as they are similar to previous changes (1)
  • stdlib/std/fmt.rv

📝 Walkthrough

Walkthrough

This release updates stdlib behavior for float formatting, weighted selection, JSON parsing, TLS config builders, and HTTP response header serialization. It also adds TLS documentation, revises the stdlib charter, and bumps the release version and changelog.

Changes

format_float precision clamping

Layer / File(s) Summary
Clamp format_float precision in scaling loop
stdlib/std/fmt.rv
format_float computes an effective clamped places value used across scaling, digit generation, and zero-padding.
Document and exercise clamped precision
docs/v2/guide/stdlib/fmt.md, examples/v2/stdlib_fmt.rv
The guide note and example program describe the clamped precision behavior and exercise a large precision input.

weighted_choice reachability fix

Layer / File(s) Summary
Floating-point weighted selection
stdlib/std/random.rv
weighted_choice sums positive weights as Float, draws via next_float(), and uses a fallback index instead of a saturating Int total.
Document and validate reachability
docs/v2/guide/stdlib/random.md, examples/v2/random_weighted_choice.rv
The guide and example describe ignored non-positive weights and the reachability of later large positive weights.

JSON UTF-8 validation and surrogate error handling

Layer / File(s) Summary
Validate UTF-8 sequences in parse_string
stdlib/std/json.rv
parse_string validates UTF-8 sequence lengths, errors on invalid or truncated bytes, and copies only validated sequences; surrogate comments and cursor initialization are updated.
Document error behavior and add regression cases
docs/v2/guide/stdlib/json.md, docs/v2/specs/std-json.md, examples/v2/use_json.rv, tests/codegen_smoke.rs
The guide and spec now describe invalid surrogate sequences as parse errors, and the example plus smoke test add an invalid-UTF-8 rejection case.

TLS checked config builders and documentation

Layer / File(s) Summary
Add checked CA/cert builder methods
stdlib/std/tls.rv
add_ca_file_checked and client_cert_checked validate FFI results and raven_tls_last_error(), while the existing methods delegate and discard the Result.
Document std/tls module and checked variants
docs/v2/guide/stdlib/tls.md, docs/v2/specs/std-tls.md, docs/v2/guide/standard-library.md, mkdocs.yml, examples/v2/tls_config_errors.rv
The new std/tls guide page, spec updates, standard-library overview entry, mkdocs nav entry, and example document and demonstrate the checked APIs.

HTTP response header sanitization

Layer / File(s) Summary
Sanitize headers during write_response
stdlib/std/http.rv
write_response filters header names via is_valid_field_name and sanitizes values via sanitize_field_value; surrounding std/http blocks are reformatted without behavior change.
Validate direct header mutation is sanitized
examples/v2/http_server_header_validation.rv, tests/codegen_smoke.rs
The example mutates headers through both chained calls and direct map access, and the output assertions and smoke test verify both paths are sanitized.

stdlib module charter update

Layer / File(s) Summary
Update shipped module list and roadmap
docs/v2/specs/stdlib-modules.md
The system/data module table, concurrency roadmap, cryptography wording, and build order summary are revised to match the shipped stdlib set.

Release version bump and changelog

Layer / File(s) Summary
Bump version and record changelog entries
Cargo.toml, CHANGELOG.md
The workspace package version changes to 2.19.10, and the changelog gains entries for 2.19.10 through 2.19.2.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant TlsConfig
  participant TLSRuntime as raven_tls FFI

  Caller->>TlsConfig: add_ca_file_checked(path)
  TlsConfig->>TLSRuntime: raven_tls_config_add_ca_file(id, path)
  TLSRuntime-->>TlsConfig: ok / 0
  TlsConfig->>TLSRuntime: raven_tls_last_error()
  alt ok == 0 or error non-empty
    TLSRuntime-->>TlsConfig: error message
    TlsConfig-->>Caller: Err(tls_error)
  else success
    TlsConfig-->>Caller: Ok(self)
  end
Loading

Possibly related PRs

  • martian56/raven#829: Builds on the prior introduction of std/tls runtime and stdlib support, which this PR extends with checked config builder variants.
  • martian56/raven#791: Also modifies write_response and response-header handling in stdlib/std/http.rv to drop invalid field names and strip control bytes from header values.
  • martian56/raven#793: Also changes Rng.weighted_choice implementation to fix weight handling and eligibility for large or non-positive weights.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is generic and doesn't clearly summarize the main changes beyond "stdlib issues". Use a specific title naming the main fixes, such as stdlib JSON, TLS, HTTP, fmt, and random updates.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed It covers summary, linked issues, and validation, but doesn't follow the template headings exactly.
Linked Issues check ✅ Passed The code/docs updates match #837#845: fmt, random, TLS, HTTP, JSON, and stdlib module docs are addressed.
Out of Scope Changes check ✅ Passed No clear unrelated code changes stand out; the changelog and version bump are ancillary to the described fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/open-issues-837-845

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
examples/v2/stdlib_fmt.rv (1)

1-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Header comment's expected output list wasn't updated for the new prints.

Lines 22-24 add two new print calls (huge.length() > 0, huge.length() < 400) that will emit true/true, but the "Prints:" comment block above still only lists the original five lines. Minor doc drift for a file meant to document expected output.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/v2/stdlib_fmt.rv` around lines 1 - 7, The header comment in std_fmt
example is out of sync with the actual output from the main example block.
Update the “Prints:” list to include the two additional boolean outputs emitted
by the new huge.length() checks, keeping the comment aligned with the print
calls in the example.
stdlib/std/fmt.rv (1)

256-258: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Doc wording drifts from format_float's actual (non-clamped) behavior.

This docstring now says "up to decimals digits", but docs/v2/guide/stdlib/fmt.md (Line 208) still says "rendered with exactly decimals digits after the decimal point". For the common case (no clamping), the function still pads to exactly decimals digits — "up to" only applies once clamping kicks in for extreme inputs. Align the wording between the two docs so users aren't confused about the normal guarantee vs. the clamped edge case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@stdlib/std/fmt.rv` around lines 256 - 258, Align the `format_float`
documentation in `fmt.rv` with the user guide wording by clarifying the normal
behavior versus the clamped edge case. Update the docstring on `format_float` so
it still reflects that, for ordinary inputs, `format_float` renders exactly
`decimals` digits after the decimal point, while only the extreme-precision case
is limited by clamping; keep the wording consistent with the corresponding
`format_float` section in the guide.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@examples/v2/stdlib_fmt.rv`:
- Around line 1-7: The header comment in std_fmt example is out of sync with the
actual output from the main example block. Update the “Prints:” list to include
the two additional boolean outputs emitted by the new huge.length() checks,
keeping the comment aligned with the print calls in the example.

In `@stdlib/std/fmt.rv`:
- Around line 256-258: Align the `format_float` documentation in `fmt.rv` with
the user guide wording by clarifying the normal behavior versus the clamped edge
case. Update the docstring on `format_float` so it still reflects that, for
ordinary inputs, `format_float` renders exactly `decimals` digits after the
decimal point, while only the extreme-precision case is limited by clamping;
keep the wording consistent with the corresponding `format_float` section in the
guide.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ffde438d-cf12-4ee1-8884-b2e4e45bf2de

📥 Commits

Reviewing files that changed from the base of the PR and between c6d2512 and 60d30d7.

⛔ Files ignored due to path filters (4)
  • Cargo.lock is excluded by !**/*.lock
  • examples/v2/random_weighted_choice.rv.out is excluded by !**/*.out
  • examples/v2/stdlib_fmt.rv.out is excluded by !**/*.out
  • examples/v2/tls_config_errors.rv.out is excluded by !**/*.out
📒 Files selected for processing (22)
  • CHANGELOG.md
  • Cargo.toml
  • docs/v2/guide/standard-library.md
  • docs/v2/guide/stdlib/fmt.md
  • docs/v2/guide/stdlib/json.md
  • docs/v2/guide/stdlib/random.md
  • docs/v2/guide/stdlib/tls.md
  • docs/v2/specs/std-json.md
  • docs/v2/specs/std-tls.md
  • docs/v2/specs/stdlib-modules.md
  • examples/v2/http_server_header_validation.rv
  • examples/v2/random_weighted_choice.rv
  • examples/v2/stdlib_fmt.rv
  • examples/v2/tls_config_errors.rv
  • examples/v2/use_json.rv
  • mkdocs.yml
  • stdlib/std/fmt.rv
  • stdlib/std/http.rv
  • stdlib/std/json.rv
  • stdlib/std/random.rv
  • stdlib/std/tls.rv
  • tests/codegen_smoke.rs

@martian56 martian56 merged commit 42b226b into main Jul 2, 2026
6 checks passed
@martian56 martian56 deleted the fix/open-issues-837-845 branch July 2, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment